function(mybuild TARGET DIR)
    set(cppnames "" PARENT_SCOPE)
    foreach(cppname ${ARGN})
        # message("append: " ${cppname})
        list(APPEND cppnames ${DIR}/${cppname})
    endforeach()
    # message("cppnames: " ${cppnames})

    add_executable(${TARGET} ${cppnames})
    set_target_properties(${TARGET}
        PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY ${DIR}
    )

    if (ASIO_DYN_LINK)
        target_link_libraries(${TARGET}
            PRIVATE
            asio
        )
    else (ASIO_DYN_LINK)
        target_include_directories(${TARGET}
            PRIVATE
            ${CMAKE_SOURCE_DIR}/include
        )
        if (UNIX)
                target_link_libraries(${TARGET}
                        PRIVATE
                        pthread
                )
        endif (UNIX)
    endif (ASIO_DYN_LINK)
endfunction(mybuild DIR TARGET)

mybuild(allocation_server allocation server.cpp)
mybuild(buffers_reference_counted buffers reference_counted.cpp)
mybuild(chat_chat_client chat chat_client.cpp)
mybuild(chat_chat_server chat chat_server.cpp)
mybuild(deferred_deferred_1 deferred deferred_1.cpp)
mybuild(deferred_deferred_2 deferred deferred_2.cpp)
mybuild(echo_async_tcp_echo_server echo async_tcp_echo_server.cpp)
mybuild(echo_async_udp_echo_server echo async_udp_echo_server.cpp)
mybuild(echo_blocking_tcp_echo_clientg echo blocking_tcp_echo_client.cpp)
mybuild(echo_blocking_tcp_echo_serverg echo blocking_tcp_echo_server.cpp)
mybuild(echo_blocking_udp_echo_clientg echo blocking_udp_echo_client.cpp)
mybuild(echo_blocking_udp_echo_serverg echo blocking_udp_echo_server.cpp)
mybuild(executors_actorg executors actor.cpp)
mybuild(executors_bank_account_1g executors bank_account_1.cpp)
mybuild(executors_bank_account_2g executors bank_account_2.cpp)
mybuild(executors_fork_joing executors fork_join.cpp)
if (!WIN32)
#TODO
mybuild(executors_pipelineg executors pipeline.cpp)
mybuild(executors_priority_schedulerg executors priority_scheduler.cpp)
endif (!WIN32)
mybuild(files_blocking_file_copyg files blocking_file_copy.cpp)
mybuild(files_async_file_copyg files async_file_copy.cpp)
mybuild(futures_daytime_clientg futures daytime_client.cpp)
mybuild(handler_tracking_async_tcp_echo_serverg handler_tracking async_tcp_echo_server.cpp)
mybuild(http_server_http_server_SOURCES
 	http server/connection.cpp server/connection_manager.cpp server/main.cpp
 	server/mime_types.cpp
 	server/reply.cpp
 	server/request_handler.cpp
 	server/request_parser.cpp
 	server/server.cpp)
mybuild(invocation_prioritised_handlersg invocation prioritised_handlers.cpp)
mybuild(iostreams_http_clientg iostreams http_client.cpp)
mybuild(multicast_receiverg multicast receiver.cpp)
mybuild(multicast_senderg multicast sender.cpp)
mybuild(nonblocking_third_party_libg nonblocking third_party_lib.cpp)
mybuild(operations_composed_1g operations composed_1.cpp)
mybuild(operations_composed_2g operations composed_2.cpp)
mybuild(operations_composed_3g operations composed_3.cpp)
mybuild(operations_composed_4g operations composed_4.cpp)
mybuild(operations_composed_5g operations composed_5.cpp)
mybuild(operations_composed_6g operations composed_6.cpp)
mybuild(operations_composed_7g operations composed_7.cpp)
mybuild(operations_composed_8g operations composed_8.cpp)
mybuild(parallel_group_ranged_wait_for_allg parallel_group ranged_wait_for_all.cpp)
mybuild(parallel_group_wait_for_allg parallel_group wait_for_all.cpp)
mybuild(parallel_group_wait_for_oneg parallel_group wait_for_one.cpp)
mybuild(parallel_group_wait_for_one_errorg parallel_group wait_for_one_error.cpp)
mybuild(parallel_group_wait_for_one_successg parallel_group wait_for_one_success.cpp)
mybuild(socks4_sync_clientg socks4 sync_client.cpp)
mybuild(timeouts_async_tcp_clientg timeouts async_tcp_client.cpp)
mybuild(timeouts_blocking_tcp_clientg timeouts blocking_tcp_client.cpp)
mybuild(timeouts_blocking_token_tcp_clientg timeouts blocking_token_tcp_client.cpp)
mybuild(timeouts_blocking_udp_clientg timeouts blocking_udp_client.cpp)
mybuild(timeouts_serverg timeouts server.cpp)
mybuild(timers_time_t_timerg timers time_t_timer.cpp)
if (!WIN32)
#TODO
mybuild(type_erasure_type_erasureg type_erasure main.cpp stdin_line_reader.cpp sleep.cpp)
endif (!WIN32)

if (!WIN32)
mybuild(fork_daemong fork daemon.cpp)
mybuild(fork_process_per_connectiong fork process_per_connection.cpp)
mybuild(local_connect_pairg local connect_pair.cpp)
mybuild(local_iostream_clientg local iostream_client.cpp)
mybuild(local_stream_serverg local stream_server.cpp)
mybuild(local_stream_clientg local stream_client.cpp)
mybuild(local_fd_passing_stream_serverg local fd_passing_stream_server.cpp)
mybuild(local_fd_passing_stream_clientg local fd_passing_stream_client.cpp)
endif(!WIN32)
# if HAVE_OPENSSL
# mybuild(ssl_clientg ssl client.cpp)
# mybuild(ssl_serverg ssl server.cpp)
# endif
# if HAVE_BOOST_COROUTINE
# mybuild(spawn_echo_serverg spawn echo_server.cpp)
# mybuild(spawn_echo_server_LDADD = $(LDADD) -lboost_coroutine -lboost_context -lboost_thread -lboost_chrono -lboost_system)
# mybuild(spawn_parallel_grepg spawn parallel_grep.cpp)
# mybuild(spawn_parallel_grep_LDADD = $(LDADD) -lboost_coroutine -lboost_context -lboost_thread -lboost_chrono -lboost_system)
# endif

# EXTRA_DIST = \
# 	handler_tracking/custom_tracking.hpp \
# 	http/server/connection.hpp \
# 	http/server/connection_manager.hpp \
# 	http/server/header.hpp \
# 	http/server/mime_types.hpp \
# 	http/server/reply.hpp \
# 	http/server/request.hpp \
# 	http/server/request_handler.hpp \
# 	http/server/request_parser.hpp \
# 	http/server/server.hpp \
# 	ssl/README \
# 	ssl/ca.pem \
# 	ssl/server.pem \
# 	ssl/dh4096.pem \
# 	type_erasure/line_reader.hpp \
# 	type_erasure/stdin_line_reader.hpp \
# 	type_erasure/sleep.hpp
